-- attack_sc_prop
-- created by zhuangsl
-- 天空战附加属性：每次攻击附带特殊属性
-- ([physics:([ ""base_attrib"":([""luck"":5]) ])]) 代表飞艇主炮攻击同时，提升5点幸运
-- ([skill:([ ""base_attrib"":([""fire"":-5]) ])]) 代表飞艇秘宝攻击同时，降低5点幸运

return {
    -- 空属性
    getEmptyProp = function()
        return {};
    end,

    -- 合并属性
    mergeSkyProp = function(data, addon)
        local result = {};

        if not data then
            result = table.deepcopy(addon);
        else
            result = table.deepcopy(data);
            local mob;

            for style, value in pairs(addon) do
                if not result[style] then
                    result[style] = {};
                end

                for rule, _ in pairs(value) do
                    mob = SkyPropM.queryRule(rule);
                    result[style][rule] = mob.mergeSkyProp(result[style][rule], value[rule]);
                end
            end
        end

        return result;
    end,

    triggerProp = function(fighter, para)
        local skillId = para["skillId"];
        local skillType = SkyShipSkillM.query(skillId, "type");

        local skyProps = SkyPropM.getFighterProp(fighter, "attack_sc_prop");


        if skillType == SHIP_SKILL_PHYSICS then
            skyProps = skyProps["physics"];
        else
            skyProps = skyProps["skill"];
        end

        if not skyProps then
            return;
        end

        -- 给敌人用的要记在敌人身上
        local enemyProps = {};
        local list = { "defenser_attrib", "defenser_permillage_attrib",
        "defenser_skill_rate", "defenser_disable_prop" };

        for rule, data in pairs(skyProps) do
            if table.indexOf(list, rule) >= 0 then
                enemyProps[rule] = data;
                skyProps[rule] = nil;
            end
        end

        if #table.keys(skyProps) > 0 then
            SkyPropM.recordRoundProp(fighter, skyProps);
        end

        if #table.keys(enemyProps) > 0 then
            SkyPropM.recordRoundProp(para["target"], enemyProps);
        end
    end,

    parseDesc = function(desc, data)
        -- 攻击附带的特殊属性，由该属性的模块解析
        local sc_prop;
        for _, key in ipairs(table.keys(data)) do
            sc_prop = data[key];
            desc = SkyPropM.parseDesc(desc, sc_prop);
        end

        return desc;
    end,
};